from drf_yasg import openapi
from .serializers import (
    OrderListSerializer,
    OrderCreateSerializer,
    OrderStatusSerializer,
    ReviewSerializer
)

OrderViewsetDocs = {
    'list': {
        'operation_summary': "获取订单列表",
        'manual_parameters': [
            openapi.Parameter(
                'status', openapi.IN_QUERY,
                description="订单状态过滤 0-待支付 1-待发货 2-待收货 3-已完成 4-已取消",
                type=openapi.TYPE_INTEGER
            ),
        ],
        'responses': {
            200: OrderListSerializer(many=True)
        }
    },
    'retrieve': {
        'operation_summary': "获取订单详情",
        'responses': {
            200: OrderListSerializer()
        }
    },
    'create': {
        'operation_summary': "创建新订单",
        'request_body': OrderCreateSerializer,
        'responses': {
            201: OrderListSerializer(),
            400: openapi.Response("参数错误示例",
                examples={"application/json": {
                    "code": "PRODUCT_NOT_FOUND",
                    "message": "商品不可用"
                }})
        }
    },
    'update_status': {
        'method': 'patch',
        'operation_summary': "更新订单状态",
        'request_body': OrderStatusSerializer,
        'responses': {
            200: OrderListSerializer(),
            403: openapi.Response("权限错误示例",
                examples={"application/json": {
                    "detail": "卖家不允许此操作"
                }})
        }
    },
    'initiate_payment': {
        'method': 'post',
        'operation_summary': "模拟支付（直接完成支付）",
        'responses': {
            200: openapi.Response("支付成功示例",
                schema=openapi.Schema(
                    type=openapi.TYPE_OBJECT,
                    properties={
                        'status': openapi.Schema(type=openapi.TYPE_STRING),
                        'order_status': openapi.Schema(type=openapi.TYPE_INTEGER)
                    }
                ))
        }
    },
    'complete_order':{
        'method': 'post',
        'operation_summary': "确认收货完成订单",
        'responses': {
            200: openapi.Response("确认收货成功",
                schema=openapi.Schema(
                    type=openapi.TYPE_OBJECT,
                    properties={
                        'status': openapi.Schema(type=openapi.TYPE_STRING),
                        'product_status': openapi.Schema(type=openapi.TYPE_INTEGER)
                    }
                )),
            400: openapi.Response("订单状态错误",
                examples={"application/json": {
                    "error": "只有待收货订单可完成"
                }})
        }
    },
}

PaymentCallbackDocs = {
    'post': {
        'operation_summary': "支付回调通知接口",
        'request_body': openapi.Schema(
            type=openapi.TYPE_OBJECT,
            required=['order_code', 'success'],
            properties={
                'order_code': openapi.Schema(type=openapi.TYPE_STRING),
                'success': openapi.Schema(type=openapi.TYPE_BOOLEAN)
            }
        ),
        'responses': {
            200: openapi.Response("处理成功",
                examples={"application/json": {"status": "success"}})
        }
    }
}

ReviewViewsetDocs = {
    'list': {
        'operation_summary': "获取订单评论列表",
        'manual_parameters': [
            openapi.Parameter(
                'order', openapi.IN_QUERY,
                description="订单ID过滤",
                type=openapi.TYPE_STRING
            )
        ],
        'responses': {
            200: ReviewSerializer(many=True)
        }
    },
    'create': {
        'operation_summary': "创建订单评论",
        'responses': {
            201: ReviewSerializer(),
            400: openapi.Response("订单状态不满足条件")
        }
    },
    'update': {
        'operation_summary': "更新评论内容",
        'request_body': openapi.Schema(
            type=openapi.TYPE_OBJECT,
            properties={
                'content': openapi.Schema(
                    type=openapi.TYPE_STRING,
                    description="评论内容"
                )
            }
        ),
        'responses': {
            200: ReviewSerializer(),
            400: openapi.Response("参数错误"),
            403: openapi.Response("无权限修改")
        }
    }
}
